function validateReview(){
    
    var regReview = /^[A-Za-z0-9'":,!?. ]{1,}$/;
    var flag = 0;
    
    if(!document.productreview.productReview.value.match(regReview)){
	document.getElementById("reviewError").innerHTML = "*Invalid Review.";   
        flag+=1;
    }
    
    if(flag >= 1){
        alert("Please double check your information.");
        return false;
    }
    else{
        return true;
    }
    
}


function validateEditUser(){
    
    var regTelNo = /^[0-9]{7,20}$/;
    var regEmail = /\b[A-z0-9._]+@\b[A-z0-9.-]+\b.\b[A-z]+\b/;
    var regHome = /^[A-Za-z0-9 ]{1,}$/;
    var regStreet = /^[A-Za-z0-9 ]{1,}$/;
    var regSubdivision = /^[A-Za-z0-9 ]{1,}$/;
    var regCity = /^[A-Za-z0-9 ]+$/;
    var regPostal = /^[0-9]{3,10}$/;
    var regCountry = /^[A-Za-z]+$/;
    var flag = 0;
    
    document.getElementById("emailError").innerHTML = "";
    document.getElementById("TelNoError").innerHTML = "";
    document.getElementById("houseError").innerHTML = "";
    document.getElementById("streetError").innerHTML = "";
    document.getElementById("subError").innerHTML = "";
    document.getElementById("cityError").innerHTML = "";
    document.getElementById("postalError").innerHTML = "";
    document.getElementById("countryError").innerHTML = "";
    
    
    if(document.editUserForm.edittelephone.value.length <= 6){
        document.getElementById("TelNoError").innerHTML = "Please enter a valid telephone number with at least 7 numbers in length.";
        flag += 1;
    }
    else if(!document.editUserForm.edittelephone.value.match(regTelNo)){
        document.getElementById("TelNoError").innerHTML = "Must contain numbers only.";
        flag += 1;
    }
    if(document.editUserForm.editemail.value.length === 0){
        document.getElementById("emailError").innerHTML = "Please enter a valid e-mail address.";
        flag += 1;
    }
    else if(!document.editUserForm.editemail.value.match(regEmail)){
        document.getElementById("emailError").innerHTML = "Must contain letters, numbers, hyphens, and underscores only.";
        flag += 1;
    }
    if(document.editUserForm.editAddressDeliveryNumber.value.length === 0){
        document.getElementById("houseError").innerHTML = "Please enter a house number.";
        flag += 1;
    }
    else if(!document.editUserForm.editAddressDeliveryNumber.value.match(regHome)){
        document.getElementById("houseError").innerHTML = "No special characters.";
        flag += 1;
    }
    if(document.editUserForm.editAddressDeliveryStreet.value.length === 0){
        document.getElementById("streetError").innerHTML = "Please enter a street name.";
        flag += 1;
    }
    else if(!document.editUserForm.editAddressDeliveryStreet.value.match(regStreet)){
        document.getElementById("streetError").innerHTML = "No special characters.";
        flag += 1;
    }
    if(document.editUserForm.editAddressDeliverySubdivision.value.length === 0){
        document.getElementById("subError").innerHTML = "Please enter a subdivision.";
        flag += 1;
    }
    else if(!document.editUserForm.editAddressDeliverySubdivision.value.match(regSubdivision)){
        document.getElementById("subError").innerHTML = "No special characters.";
        flag += 1;
    }
    if(document.editUserForm.editAddressDeliveryCity.value.length === 0){
        document.getElementById("cityError").innerHTML = "Please enter a city.";
        flag += 1;
    }
    else if(!document.editUserForm.editAddressDeliveryCity.value.match(regCity)){
        document.getElementById("cityError").innerHTML = "No special characters.";
        flag += 1;
    }
    if(document.editUserForm.editAddressDeliveryPostal.value.length <= 2){
        document.getElementById("postalError").innerHTML = "Please enter a postal code.";
        flag += 1;
    }
    else if(!document.editUserForm.editAddressDeliveryPostal.value.match(regPostal)){
        document.getElementById("postalError").innerHTML = "Must contain 3 - 10 numbers in length.";
        flag += 1;    
    }
    if(document.editUserForm.editAddressDeliveryCountry.value.length === 0){
        document.getElementById("countryError").innerHTML = "Please enter a country.";
        flag += 1;
    }
    else if(!document.editUserForm.editAddressDeliveryCountry.value.match(regCountry)){
        document.getElementById("countryError").innerHTML = "No numbers and special characters.";
        flag += 1;
    }
    
    if(flag >= 1){
        alert("Please double check your information.");
        return false;
    }
    else{
        return true;
    }
        
    
}


function validateaudioCD(){
    var flag = 0;
    var regTitle = /^[A-Za-z0-9"':,!?. ]{1,}$/;
    var regSummary = /^[A-Za-z0-9'":,!?. ]{1,}$/;
    var regPrice = /^[0-9]{1,}$/;
    var regStock = /^[0-9]{1,}$/;
    
    document.getElementById("titleError").innerHTML = "";
    document.getElementById("summaryError").innerHTML = "";
    document.getElementById("priceError").innerHTML = "";
    document.getElementById("stockError").innerHTML = "";
    
    
    if(document.audioCDAddProduct.audioCDTitle.value.length == 0){
	document.getElementById("titleError").innerHTML = "*Title is required."; 
        flag+=1;
    }
    else if(!document.audioCDAddProduct.audioCDTitle.value.match(regTitle)){
	document.getElementById("titleError").innerHTML = "*Invalid Title.";   
        flag+=1;
    }
    if(document.audioCDAddProduct.audioCDSummary.value.length == 0){
	document.getElementById("summaryError").innerHTML = "*Summary is required."; 
        flag+=1;
    }
    else if(!document.audioCDAddProduct.audioCDSummary.value.match(regSummary)){
	document.getElementById("summaryError").innerHTML = "*Invalid Summary.";   
        flag+=1;
    }
    if(document.audioCDAddProduct.audioCDPrice.value.length == 0){
	document.getElementById("priceError").innerHTML = "*Price is required."; 
        flag+=1;
    }
    else if(!document.audioCDAddProduct.audioCDPrice.value.match(regPrice)){
	document.getElementById("priceError").innerHTML = "*Invalid Price.";   
        flag+=1;
    }
    if(document.audioCDAddProduct.audioCDStock.value.length == 0){
	document.getElementById("stockError").innerHTML = "*Stock is required."; 
        flag+=1;
    }
    else if(!document.audioCDAddProduct.audioCDStock.value.match(regStock)){
	document.getElementById("stockError").innerHTML = "*Invalid Stock.";   
        flag+=1;
    }
    
    if(flag >= 1){
        alert("Please double check your information.");
        return false;
    }
    else{
        form.action="addAudioCDServlet";
        return true;
    }
    
}


function validateDVD(){
    var flag = 0;
    var regTitle = /^[A-Za-z0-9"':,!?. ]{1,}$/;
    var regSummary = /^[A-Za-z0-9'":,!?. ]{1,}$/;
    var regPrice = /^[0-9]{1,}$/;
    var regStock = /^[0-9]{1,}$/;
    
    document.getElementById("titleError").innerHTML = "";
    document.getElementById("summaryError").innerHTML = "";
    document.getElementById("priceError").innerHTML = "";
    document.getElementById("stockError").innerHTML = "";
    
    
    if(document.dvdAddProduct.dvdTitle.value.length == 0){
	document.getElementById("titleError").innerHTML = "*Title is required."; 
        flag+=1;
    }
    else if(!document.dvdAddProduct.dvdTitle.value.match(regTitle)){
	document.getElementById("titleError").innerHTML = "*Invalid Title.";   
        flag+=1;
    }
    if(document.dvdAddProduct.dvdSummary.value.length == 0){
	document.getElementById("summaryError").innerHTML = "*Summary is required."; 
        flag+=1;
    }
    else if(!document.dvdAddProduct.dvdSummary.value.match(regSummary)){
	document.getElementById("summaryError").innerHTML = "*Invalid Summary.";   
        flag+=1;
    }
    if(document.dvdAddProduct.dvdPrice.value.length == 0){
	document.getElementById("priceError").innerHTML = "*Price is required."; 
        flag+=1;
    }
    else if(!document.dvdAddProduct.dvdPrice.value.match(regPrice)){
	document.getElementById("priceError").innerHTML = "*Invalid Price.";   
        flag+=1;
    }
    if(document.dvdAddProduct.dvdStock.value.length == 0){
	document.getElementById("stockError").innerHTML = "*Stock is required."; 
        flag+=1;
    }
    else if(!document.dvdAddProduct.dvdStock.value.match(regStock)){
	document.getElementById("stockError").innerHTML = "*Invalid Stock.";   
        flag+=1;
    }
    
    if(flag >= 1){
        alert("Please double check your information.");
        return false;
    }
    else{
        form.action="addDVDServlet";
        return true;
    }
    
}


function validatebook(){
    var flag = 0;
    var regTitle = /^[A-Za-z0-9"':,!?. ]{1,}$/;
    var regSummary = /^[A-Za-z0-9'":,!?. ]{1,}$/;
    var regPrice = /^[0-9]{1,}$/;
    var regStock = /^[0-9]{1,}$/;
    
    document.getElementById("titleError").innerHTML = "";
    document.getElementById("summaryError").innerHTML = "";
    document.getElementById("priceError").innerHTML = "";
    document.getElementById("stockError").innerHTML = "";
    
    
    if(document.bookAddProduct.bookTitle.value.length == 0){
	document.getElementById("titleError").innerHTML = "*Title is required."; 
        flag+=1;
    }
    else if(!document.bookAddProduct.bookTitle.value.match(regTitle)){
	document.getElementById("titleError").innerHTML = "*Invalid Title.";   
        flag+=1;
    }
    if(document.bookAddProduct.bookSummary.value.length == 0){
	document.getElementById("summaryError").innerHTML = "*Summary is required."; 
        flag+=1;
    }
    else if(!document.bookAddProduct.bookSummary.value.match(regSummary)){
	document.getElementById("summaryError").innerHTML = "*Invalid Summary.";   
        flag+=1;
    }
    if(document.bookAddProduct.bookPrice.value.length == 0){
	document.getElementById("priceError").innerHTML = "*Price is required."; 
        flag+=1;
    }
    else if(!document.bookAddProduct.bookPrice.value.match(regPrice)){
	document.getElementById("priceError").innerHTML = "*Invalid Price.";   
        flag+=1;
    }
    if(document.bookAddProduct.bookStock.value.length == 0){
	document.getElementById("stockError").innerHTML = "*Stock is required."; 
        flag+=1;
    }
    else if(!document.bookAddProduct.bookStock.value.match(regStock)){
	document.getElementById("stockError").innerHTML = "*Invalid Stock.";   
        flag+=1;
    }
    
    if(flag >= 1){
        alert("Please double check your information.");
        return false;
    }
    else{
        form.action="addBookServlet";
        return true;
    }
    
}


function validatemagazine(){
    var flag = 0;
    var regTitle = /^[A-Za-z0-9"':,!?. ]{1,}$/;
    var regSummary = /^[A-Za-z0-9'":,!?. ]{1,}$/;
    var regPrice = /^[0-9]{1,}$/;
    var regStock = /^[0-9]{1,}$/;
    
    document.getElementById("titleError").innerHTML = "";
    document.getElementById("summaryError").innerHTML = "";
    document.getElementById("priceError").innerHTML = "";
    document.getElementById("stockError").innerHTML = "";
    
    
    if(document.magazineAddProduct.magazineTitle.value.length == 0){
	document.getElementById("titleError").innerHTML = "*Title is required."; 
        flag+=1;
    }
    else if(!document.magazineAddProduct.magazineTitle.value.match(regTitle)){
	document.getElementById("titleError").innerHTML = "*Invalid Title.";   
        flag+=1;
    }
    if(document.magazineAddProduct.magazineSummary.value.length == 0){
	document.getElementById("summaryError").innerHTML = "*Summary is required."; 
        flag+=1;
    }
    else if(!document.magazineAddProduct.magazineSummary.value.match(regSummary)){
	document.getElementById("summaryError").innerHTML = "*Invalid Summary.";   
        flag+=1;
    }
    if(document.magazineAddProduct.magazinePrice.value.length == 0){
	document.getElementById("priceError").innerHTML = "*Price is required."; 
        flag+=1;
    }
    else if(!document.magazineAddProduct.magazinePrice.value.match(regPrice)){
	document.getElementById("priceError").innerHTML = "*Invalid Price.";   
        flag+=1;
    }
    if(document.magazineAddProduct.magazineStock.value.length == 0){
	document.getElementById("stockError").innerHTML = "*Stock is required."; 
        flag+=1;
    }
    else if(!document.magazineAddProduct.magazineStock.value.match(regStock)){
	document.getElementById("stockError").innerHTML = "*Invalid Stock.";   
        flag+=1;
    }
    
    if(flag >= 1){
        alert("Please double check your information.");
        return false;
    }
    else{
        form.action="addMagazineServlet";
        return true;
    }
    
}


function validateChangePassword(){
    
    var flag = 0;
    var regPass = /((?=.*\d)(?=.*[A-Z])(?=.*\W).{8,})/;
    
    if(document.changepassForm.NewPassword.value.length <= 7){
        document.getElementById("passError").innerHTML = "Password must be at least 8 characters in length.";
        flag += 1;
    }
    else if(!document.changepassForm.NewPassword.value.match(regPass)){
        document.getElementById("passError").innerHTML = "Must contain at least 1 uppercase letter, 1 number, and 1 special character.";
        flag += 1;
    }
    if(document.changepassForm.NewPassword.value !== document.changepassForm.retypeNewPassword.value){
        document.getElementById("retypeError").innerHTML = "Passwords do not match.";
        flag += 1;
    }
    
    if(flag >= 1){
        alert("Please double check your information.");
        return false;
    }
    else{
        form.action="changePasswordServlet";
        return true;
    }
    
}

function validateNewPassword(){
    var regPass = /((?=.*\d)(?=.*[A-Z])(?=.*\W).{8,})/;
    
    if(document.changepassForm.NewPassword.value.length <= 7)
    	document.getElementById("passError").innerHTML = "Password must be at least 8 characters in length.";
    else if(!document.changepassForm.NewPassword.value.match(regPass))
        document.getElementById("passError").innerHTML = "Must contain at least 1 uppercase letter, 1 number, and 1 special character.";
    else{
    	document.getElementById("passError").innerHTML = "";
        return true;
    }
    return false;
}
function validateNewPasswords(){
    if(document.changepassForm.NewPassword.value !== document.changepassForm.retypeNewPassword.value)
    	document.getElementById("retypeError").innerHTML = "Passwords do not match.";
    else{
    	document.getElementById("retypeError").innerHTML = "";
        return true;
    }
    return false;
}

function validateFirstName(){
    var regName = /^[A-Za-z ]{1,}$/;
    
    if(document.registrationForm.nameFirst.value.length === 0)
        document.getElementById("nameError").innerHTML = "Please enter your first name.";
    else if(!document.registrationForm.nameFirst.value.match(regName))
            document.getElementById("nameError").innerHTML = "First name must contain letters only.";
    else{
	document.getElementById("nameError").innerHTML = "";
        return true;
    }
    return false;
}
function validateMI(){
    var regMI = /^[A-Za-z]+$/;
    
    if(document.registrationForm.nameMiddleI.value.length !== 0){
        if(!document.registrationForm.nameMiddleI.value.match(regMI))
            document.getElementById("nameError").innerHTML = "Middle initial must contain letters only.";
    }
    else{
	document.getElementById("nameError").innerHTML = "";
        return true;
    }
    return false;
}
function validateLastName(){
    var regName = /^[A-Za-z ]{1,}$/;
    
    if(document.registrationForm.nameLast.value.length === 0)
        document.getElementById("nameError").innerHTML = "Please enter your last name.";
    else if(!document.registrationForm.nameLast.value.match(regName))
            document.getElementById("nameError").innerHTML = "Last name must contain letters only.";
    else{
	document.getElementById("nameError").innerHTML = "";
        return true;
    }
    return false;
}
function validateUsername(){
    var regUser = /^[A-Za-z0-9]{8,}$/;
    
    if(document.registrationForm.username.value.length <= 7)
	document.getElementById("userError").innerHTML = "Username must be at least 8 characters in length.";        
    else if(!document.registrationForm.username.value.match(regUser))
        document.getElementById("userError").innerHTML = "Must contain letters and numbers only.";
    else{
	document.getElementById("userError").innerHTML = "";
        return true;
    }
    return false;
}
function validatePassword(){
    var username = document.registrationForm.username.value;
    var regPass = /((?=.*\d)(?=.*[A-Z])(?=.*\W).{8,})/;
    
    if(document.registrationForm.password.value.length <= 7)
    	document.getElementById("passError").innerHTML = "Password must be at least 8 characters in length.";
    else if(document.registrationForm.password.value.indexOf(username) !== -1)
        document.getElementById("passError").innerHTML = "Password must not contain your username.";
    else if(!document.registrationForm.password.value.match(regPass))
        document.getElementById("passError").innerHTML = "Must contain at least 1 uppercase letter, 1 number, and 1 special character.";
    else{
    	document.getElementById("passError").innerHTML = "";
        return true;
    }
    return false;
}
function validatePasswords(){
    if(document.registrationForm.password.value !== document.registrationForm.retypePassword.value)
    	document.getElementById("retypeError").innerHTML = "Passwords do not match.";
    else{
    	document.getElementById("retypeError").innerHTML = "";
        return true;
    }
    return false;
}
function validateTelephone(){
    var regTelNo = /^[0-9]{7,20}$/;
    
    if(document.registrationForm.telephone.value.length <= 6)
    	document.getElementById("TelNoError").innerHTML = "Please enter a valid telephone number with at least 7 numbers in length.";
    else if(!document.registrationForm.telephone.value.match(regTelNo))
        document.getElementById("TelNoError").innerHTML = "Must contain numbers only.";
    else{
    	document.getElementById("TelNoError").innerHTML = "";
        return true;
    }
    return false;
}
function validateEmail(){
    var regEmail = /\b[A-z0-9._]+@\b[A-z0-9.-]+\b.\b[A-z]+\b/;
    
    if(document.registrationForm.email.value.length === 0)
        document.getElementById("emailError").innerHTML = "Please enter a valid e-mail address.";
    else if(!document.registrationForm.email.value.match(regEmail))
        document.getElementById("emailError").innerHTML = "Must contain letters, numbers, hyphens, and underscores only.";
    else{
    	document.getElementById("emailError").innerHTML = "";
        return true;
    }
    return false;
}
function validateAddressDeliveryNumber(){
    var regHome = /^[A-Za-z0-9 ]{1,}$/;
    
    if(document.registrationForm.AddressDeliveryNumber.value.length === 0)
        document.getElementById("houseError").innerHTML = "Please enter a house number.";
    else if(!document.registrationForm.AddressDeliveryNumber.value.match(regHome))
        document.getElementById("houseError").innerHTML = "No special characters.";
    else{
    	document.getElementById("houseError").innerHTML = "";
        return true;
    }
    return false;
}
function validateAddressBillNumber(){
    var regHome = /^[A-Za-z0-9 ]{1,}$/;
    
    if(document.registrationForm.addressBillNumber.value.length === 0)
        document.getElementById("cHouseError").innerHTML = "Please enter a house number.";
    else if(!document.registrationForm.addressBillNumber.value.match(regHome))
        document.getElementById("cHouseError").innerHTML = "No special characters.";
    else{
    	document.getElementById("cHouseError").innerHTML = "";
        return true;
    }
    return false;
}  
function validateAddressDeliveryStreet(){
    var regStreet = /^[A-Za-z0-9 ]{1,}$/;
   
    if(document.registrationForm.AddressDeliveryStreet.value.length === 0)
        document.getElementById("streetError").innerHTML = "Please enter a street name.";
    else if(!document.registrationForm.AddressDeliveryStreet.value.match(regStreet))
        document.getElementById("streetError").innerHTML = "No special characters.";
    else{
    	document.getElementById("streetError").innerHTML = "";
        return true;
    }
    return false;
} 
function validateAddressBillStreet(){
    var regStreet = /^[A-Za-z0-9 ]{1,}$/;
    
    if(document.registrationForm.addressBillStreet.value.length === 0)
        document.getElementById("cStreetError").innerHTML = "Please enter a street name.";
    else if(!document.registrationForm.addressBillStreet.value.match(regStreet))
        document.getElementById("cStreetError").innerHTML = "No special characters.";
    else{
    	document.getElementById("cStreetError").innerHTML = "";
        return true;
    }
    return false;
} 
function validateAddressDeliverySubdivision(){
    var regSubdivision = /^[A-Za-z0-9 ]{1,}$/;
    
    if(document.registrationForm.AddressDeliverySubdivision.value.length === 0)
        document.getElementById("subError").innerHTML = "Please enter a subdivision.";
    else if(!document.registrationForm.AddressDeliverySubdivision.value.match(regSubdivision))
        document.getElementById("subError").innerHTML = "No special characters.";
    else{
    	document.getElementById("subError").innerHTML = "";
        return true;
    }
    return false;
} 
function validateAddressBillSubdivision(){
    var regSubdivision = /^[A-Za-z0-9 ]{1,}$/;
    
    if(document.registrationForm.addressBillSubdivision.value.length === 0)
        document.getElementById("cSubError").innerHTML = "Please enter a subdivision.";
    else if(!document.registrationForm.addressBillSubdivision.value.match(regSubdivision))
        document.getElementById("cSubError").innerHTML = "No numbers and special characters.";
    else{
    	document.getElementById("cSubError").innerHTML = "";
        return true;
    }
    return false;
} 
function validateAddressDeliveryCity(){
    var regCity = /^[A-Za-z0-9 ]+$/;
    
    if(document.registrationForm.AddressDeliveryCity.value.length === 0)
        document.getElementById("cityError").innerHTML = "Please enter a city.";
    else if(!document.registrationForm.AddressDeliveryCity.value.match(regCity))
        document.getElementById("cityError").innerHTML = "No special characters.";
    else{
    	document.getElementById("cityError").innerHTML = "";
        return true;
    }
    return false;
} 
function validateAddressBillCity(){
    var regCity = /^[A-Za-z0-9 ]+$/;
    
    if(document.registrationForm.addressBillCity.value.length === 0)
        document.getElementById("cCityError").innerHTML = "Please enter a city.";
    else if(!document.registrationForm.addressBillCity.value.match(regCity))
        document.getElementById("cCityError").innerHTML = "No special characters.";
    else{
    	document.getElementById("cCityError").innerHTML = "";
        return true;
    }
    return false;
}
function validateAddressDeliveryPostal(){
    var regPostal = /^[0-9]{3,10}$/;
    
    if(document.registrationForm.AddressDeliveryPostal.value.length === 0)
        document.getElementById("postalError").innerHTML = "Please enter a postal code.";
    else if(!document.registrationForm.AddressDeliveryPostal.value.match(regPostal))
    	document.getElementById("postalError").innerHTML = "Must contain 3 - 10 numbers in length.";
    else{
    	document.getElementById("postalError").innerHTML = "";
        return true;
    }
    return false;
}
function validateAddressBillPostal(){
    var regPostal= /^[0-9]{3,10}$/;
    
    if(document.registrationForm.addressBillPostal.value.length === 0)
        document.getElementById("cPostalError").innerHTML = "Please enter a postal code.";
    else if(!document.registrationForm.addressBillPostal.value.match(regPostal))
    	document.getElementById("cPostalError").innerHTML = "Must contain 3 - 10 numbers in length.";
    else{
    	document.getElementById("cPostalError").innerHTML = "";
        return true;
    }
    return false;
}
function validateAddressDeliveryCountry(){
    var regCountry = /^[A-Za-z]+$/;
    
    if(document.registrationForm.AddressDeliveryCountry.value.length === 0)
        document.getElementById("countryError").innerHTML = "Please enter a country.";
    else if(!document.registrationForm.AddressDeliveryCountry.value.match(regCountry))
        document.getElementById("countryError").innerHTML = "No numbers and special characters.";
    else{
    	document.getElementById("countryError").innerHTML = "";
        return true;
    }
    return false;
}
function validateAddressBillCountry(){
    var regCountry = /^[A-Za-z]+$/;
    
    if(document.registrationForm.addressBillCountry.value.length === 0)
        document.getElementById("cCountryError").innerHTML = "Please enter a country.";
    else if(!document.registrationForm.addressBillCountry.value.match(regCountry))
        document.getElementById("cCountryError").innerHTML = "No numbers and special characters.";
    else{
    	document.getElementById("cCountryError").innerHTML = "";
        return true;
    }
    return false;
}
function validateCreditName(){
    var regCreditName = /^[A-Za-z. ]{1,}$/;
    
    if(document.registrationForm.creditName.value.length === 0)
        document.getElementById("cNameError").innerHTML = "Please enter name on credit card.";
    else if(!document.registrationForm.creditName.value.match(regCreditName))
        document.getElementById("cNameError").innerHTML = "No numbers and special characters.";
    else{
    	document.getElementById("cNameError").innerHTML = "";
        return true;
    }
    return false;
}
function validateCreditNumber(){
    var regCreditNumber = /^[0-9]+$/;
    
    if(document.registrationForm.creditNumber.value.length <= 15)
        document.getElementById("cNumError").innerHTML = "Please enter credit card number with an exact length of 16.";
    else if(!document.registrationForm.creditNumber.value.match(regCreditNumber))
        document.getElementById("cNumError").innerHTML = "Numbers only.";
    else{
    	document.getElementById("cNumError").innerHTML = "";
        return true;
    }
    return false;
}
function validateExpiration(){
    var regExpiration = /^[0-9]+$/;
    
    if(document.registrationForm.creditMonth.value.length === 0 || document.registrationForm.creditYear.value.length === 0)
        document.getElementById("cExpireError").innerHTML = "Please enter an expiration date.";
    else if(document.registrationForm.creditMonth.value === 0 || document.registrationForm.creditMonth.value >= 13)
        document.getElementById("cExpireError").innerHTML = "Please enter a month from 1 - 12.";
    else if(document.registrationForm.creditYear.value <= 2012)
        document.getElementById("cExpireError").innerHTML = "Please enter a year from 2013 and above.";
    else if(!document.registrationForm.creditMonth.value.match(regExpiration) || !document.registrationForm.creditYear.value.match(regExpiration))
        document.getElementById("cExpireError").innerHTML = "Numbers only.";
    else{
    	document.getElementById("cExpireError").innerHTML = "";
        return true;
    }
    return false;
}
function validateRegistration(){
    //alert("sdg"+form['email'].value);
    var flag = 0;
    var regName = /^[A-Za-z ]{1,}$/;
    var regMI = /^[A-Za-z]+$/;
    var regUser = /^[A-Za-z0-9]{8,}$/;
    var username = document.registrationForm.username.value;
    var regPass = /((?=.*\d)(?=.*[A-Z])(?=.*\W).{8,})/;
    var regTelNo = /^[0-9]{7,20}$/;
    var regEmail = /\b[A-z0-9._]+@\b[A-z0-9.-]+\b.\b[A-z]+\b/;
    var regHome = /^[A-Za-z0-9 ]{1,}$/;
    var regStreet = /^[A-Za-z0-9 ]{1,}$/;
    var regSubdivision = /^[A-Za-z0-9 ]{1,}$/;
    var regCity = /^[A-Za-z0-9 ]+$/;
    var regPostal = /^[0-9]{3,10}$/;
    var regCountry = /^[A-Za-z]+$/;
    var regCreditName = /^[A-Za-z. ]{1,}$/;
    var regCreditNumber = /^[0-9]+$/;
    var regExpiration = /^[0-9]+$/;
    
    document.getElementById("nameError").innerHTML = "";
    document.getElementById("userError").innerHTML = "";
    document.getElementById("passError").innerHTML = "";
    document.getElementById("emailError").innerHTML = "";
    document.getElementById("TelNoError").innerHTML = "";
    document.getElementById("houseError").innerHTML = "";
    document.getElementById("streetError").innerHTML = "";
    document.getElementById("subError").innerHTML = "";
    document.getElementById("cityError").innerHTML = "";
    document.getElementById("postalError").innerHTML = "";
    document.getElementById("countryError").innerHTML = "";
    document.getElementById("cNameError").innerHTML = "";
    document.getElementById("cNumError").innerHTML = "";
    document.getElementById("cExpireError").innerHTML = "";
    document.getElementById("cHouseError").innerHTML = "";
    document.getElementById("cStreetError").innerHTML = "";
    document.getElementById("cSubError").innerHTML = "";
    document.getElementById("cCityError").innerHTML = "";
    document.getElementById("cPostalError").innerHTML = "";
    document.getElementById("cCountryError").innerHTML = "";    
     
    if(document.registrationForm.nameFirst.value.length === 0){
        document.getElementById("nameError").innerHTML = "Please enter your first name.";
        flag += 1;
    }
    else if(!document.registrationForm.nameFirst.value.match(regName)){
        document.getElementById("nameError").innerHTML = "First name must contain letters only.";
        flag += 1;
    }
    if(document.registrationForm.nameMiddleI.value.length !== 0){
        if(!document.registrationForm.nameMiddleI.value.match(regMI)){
            document.getElementById("nameError").innerHTML = "Middle initial must contain letters only.";
            flag += 1;
        }
    }
    if(document.registrationForm.nameLast.value.length === 0){
        document.getElementById("nameError").innerHTML = "Please enter your last name.";
        flag += 1;
    }
    else if(!document.registrationForm.nameLast.value.match(regName)){
        document.getElementById("nameError").innerHTML = "Last name must contain letters only.";
        flag += 1;
    }
    if(document.registrationForm.nameFirst.value.length === 0 || document.registrationForm.nameLast.value.length === 0){
        document.getElementById("nameError").innerHTML = "*Please enter your full name.";
        flag += 1;
    } 
    if(document.registrationForm.username.value.length <= 7){
            document.getElementById("userError").innerHTML = "Username must be at least 8 characters in length.";        
            flag += 1;
    }
    else if(!document.registrationForm.username.value.match(regUser)){
        document.getElementById("userError").innerHTML = "Must contain letters and numbers only.";
        flag += 1;
    }
    if(document.registrationForm.password.value.length <= 7){
        document.getElementById("passError").innerHTML = "Password must be at least 8 characters in length.";
        flag += 1;
    }
    else if(document.registrationForm.password.value.indexOf(username) !== -1){
        document.getElementById("passError").innerHTML = "Password must not contain your username.";
        flag += 1;
    }
    else if(!document.registrationForm.password.value.match(regPass)){
        document.getElementById("passError").innerHTML = "Must contain at least 1 uppercase letter, 1 number, and 1 special character.";
        flag += 1;
    }
    if(document.registrationForm.password.value !== document.registrationForm.retypePassword.value){
        document.getElementById("retypeError").innerHTML = "Passwords do not match.";
        flag += 1;
    }
    if(document.registrationForm.telephone.value.length <= 6){
        document.getElementById("TelNoError").innerHTML = "Please enter a valid telephone number with at least 7 numbers in length.";
        flag += 1;
    }
    else if(!document.registrationForm.telephone.value.match(regTelNo)){
        document.getElementById("TelNoError").innerHTML = "Must contain numbers only.";
        flag += 1;
    }
    if(document.registrationForm.email.value.length === 0){
        document.getElementById("emailError").innerHTML = "Please enter a valid e-mail address.";
        flag += 1;
    }
    else if(!document.registrationForm.email.value.match(regEmail)){
        document.getElementById("emailError").innerHTML = "Must contain letters, numbers, hyphens, and underscores only.";
        flag += 1;
    }
    if(document.registrationForm.AddressDeliveryNumber.value.length === 0){
        document.getElementById("houseError").innerHTML = "Please enter a house number.";
        flag += 1;
    }
    else if(!document.registrationForm.AddressDeliveryNumber.value.match(regHome)){
        document.getElementById("houseError").innerHTML = "No special characters.";
        flag += 1;
    }
    if(document.registrationForm.addressBillNumber.value.length === 0){
        document.getElementById("cHouseError").innerHTML = "Please enter a house number.";
        flag += 1;
    }
    else if(!document.registrationForm.addressBillNumber.value.match(regHome)){
        document.getElementById("cHouseError").innerHTML = "No special characters.";
        flag += 1;
    }
    if(document.registrationForm.AddressDeliveryStreet.value.length === 0){
        document.getElementById("streetError").innerHTML = "Please enter a street name.";
        flag += 1;
    }
    else if(!document.registrationForm.AddressDeliveryStreet.value.match(regStreet)){
        document.getElementById("streetError").innerHTML = "No special characters.";
        flag += 1;
    }
    if(document.registrationForm.addressBillStreet.value.length === 0){
        document.getElementById("cStreetError").innerHTML = "Please enter a street name.";
        flag += 1;
    }
    else if(!document.registrationForm.addressBillStreet.value.match(regStreet)){
        document.getElementById("cStreetError").innerHTML = "No special characters.";
        flag += 1;
    }
    if(document.registrationForm.AddressDeliverySubdivision.value.length === 0){
        document.getElementById("subError").innerHTML = "Please enter a subdivision.";
        flag += 1;
    }
    else if(!document.registrationForm.AddressDeliverySubdivision.value.match(regSubdivision)){
        document.getElementById("subError").innerHTML = "No special characters.";
        flag += 1;
    }
    if(document.registrationForm.addressBillSubdivision.value.length === 0){
        document.getElementById("cSubError").innerHTML = "Please enter a subdivision.";
        flag += 1;
    }
    else if(!document.registrationForm.addressBillSubdivision.value.match(regSubdivision)){
        document.getElementById("cSubError").innerHTML = "No numbers and special characters.";
        flag += 1;
    }
    if(document.registrationForm.AddressDeliveryCity.value.length === 0){
        document.getElementById("cityError").innerHTML = "Please enter a city.";
        flag += 1;
    }
    else if(!document.registrationForm.AddressDeliveryCity.value.match(regCity)){
        document.getElementById("cityError").innerHTML = "No special characters.";
        flag += 1;
    }
    if(document.registrationForm.addressBillCity.value.length === 0){
        document.getElementById("cCityError").innerHTML = "Please enter a city.";
        flag += 1;
    }
    else if(!document.registrationForm.addressBillCity.value.match(regCity)){
        document.getElementById("cCityError").innerHTML = "No special characters.";
        flag += 1;
    }
    if(document.registrationForm.AddressDeliveryPostal.value.length <= 2){
        document.getElementById("postalError").innerHTML = "Please enter a postal code.";
        flag += 1;
    }
    else if(!document.registrationForm.AddressDeliveryPostal.value.match(regPostal)){
        document.getElementById("postalError").innerHTML = "Must contain 3 - 10 numbers in length.";
        flag += 1;    
    }
    if(document.registrationForm.addressBillPostal.value.length <= 2){
        document.getElementById("cPostalError").innerHTML = "Please enter a postal code.";
        flag += 1;
    }
    else if(!document.registrationForm.addressBillPostal.value.match(regPostal)){
        document.getElementById("cPostalError").innerHTML = "Must contain 3 - 10 numbers in length.";
        flag += 1;   
    }
    if(document.registrationForm.AddressDeliveryCountry.value.length === 0){
        document.getElementById("countryError").innerHTML = "Please enter a country.";
        flag += 1;
    }
    else if(!document.registrationForm.AddressDeliveryCountry.value.match(regCountry)){
        document.getElementById("countryError").innerHTML = "No numbers and special characters.";
        flag += 1;
    }
    if(document.registrationForm.addressBillCountry.value.length === 0){
        document.getElementById("cCountryError").innerHTML = "Please enter a country.";
        flag += 1;
    }
    else if(!document.registrationForm.addressBillCountry.value.match(regCountry)){
        document.getElementById("cCountryError").innerHTML = "No numbers and special characters.";
        flag += 1;
    }
    if(document.registrationForm.creditName.value.length === 0){
        document.getElementById("cNameError").innerHTML = "Please enter name on credit card.";
        flag += 1;
    }
    else if(!document.registrationForm.creditName.value.match(regCreditName)){
        document.getElementById("cNameError").innerHTML = "No numbers and special characters.";
        flag += 1;
    }
    if(document.registrationForm.creditNumber.value.length <= 15){
        document.getElementById("cNumError").innerHTML = "Please enter credit card number with an exact length of 16.";
        flag += 1;
    }
    else if(!document.registrationForm.creditNumber.value.match(regCreditNumber)){
        document.getElementById("cNumError").innerHTML = "Numbers only.";
        flag += 1;
    }
    if(document.registrationForm.creditMonth.value.length === 0 || document.registrationForm.creditYear.value.length === 0){
        document.getElementById("cExpireError").innerHTML = "Please enter an expiration date.";
        flag += 1;
    }
    else if(document.registrationForm.creditMonth.value === 0 || document.registrationForm.creditMonth.value >= 13){
        document.getElementById("cExpireError").innerHTML = "Please enter a month from 1 - 12.";
        flag += 1;
    }
    else if(document.registrationForm.creditYear.value <= 2012){
        document.getElementById("cExpireError").innerHTML = "Please enter a year from 2013 and above.";
        flag += 1;
    }
    else if(!document.registrationForm.creditMonth.value.match(regExpiration) || !document.registrationForm.creditYear.value.match(regExpiration)){
        document.getElementById("cExpireError").innerHTML = "Numbers only.";    
        flag += 1;
    }
    
    if(flag >= 1){
        alert("Please double check your information.");
        return false;
    }
    else{
        form.action="registerServlet";
        return true;
    }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function validateRegister(form){
    //alert("sdg"+form['email'].value);
    var flag = 0;
    var regUser = /\b[A-z0-9]{8,15}\b/;
    var regPass = /^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=[^\W]*\W)(?=.*[\d\W]).*$/;
    var regTelNo = /\b[0-9]{7,20}\b/;
    var regEmail = /\b[A-z0-9._]+@\b[A-z0-9.-]+\b.\b[A-z]+\b/;
    var regPostal = /\b[0-9]{3,10}\b/;
    var regCreditCardNumber = /\b[0-9]{16,16}\b/;
    var regExpiration = /\b[0-9]{1,4}\b/;
    var name = form['nameFirst'].value + " " + form['nameMiddleI'].value + ". " + form['nameLast'].value;
    
    document.getElementById("nameError").innerHTML = "";
    document.getElementById("userError").innerHTML = "";
    document.getElementById("passError").innerHTML = "";
    document.getElementById("emailError").innerHTML = "";
    document.getElementById("TelNoError").innerHTML = "";
    document.getElementById("houseError").innerHTML = "";
    document.getElementById("streetError").innerHTML = "";
    document.getElementById("subError").innerHTML = "";
    document.getElementById("cityError").innerHTML = "";
    document.getElementById("postalError").innerHTML = "";
    document.getElementById("countryError").innerHTML = "";
    document.getElementById("cNameError").innerHTML = "";
    document.getElementById("cNumError").innerHTML = "";
    document.getElementById("cExpireError").innerHTML = "";
    document.getElementById("cHouseError").innerHTML = "";
    document.getElementById("cStreetError").innerHTML = "";
    document.getElementById("cSubError").innerHTML = "";
    document.getElementById("cCityError").innerHTML = "";
    document.getElementById("cPostalError").innerHTML = "";
    document.getElementById("cCountryError").innerHTML = "";    
    
    if(form['nameFirst'].value.length === 0 || form['nameLast'].value.length === 0){
        flag += 1;
        document.getElementById("nameError").innerHTML = "*Please enter your full name.";
    }  
    if(form['username'].value.length === 0 || !document.forms["registrationForm"]["username"].value.match(regUser)){
        flag += 1;
        document.getElementById("userError").innerHTML = "*Username must be 8 - 15 characters in length.";
    } 
    if(form['password'].value.length === 0 || !document.forms["registrationForm"]["password"].value.match(regPass)){
        document.getElementById("passError").innerHTML = "*Password must be at least 8 characters and must contain at least 1 uppercase letter, 1 number, and 1 special character.";
        flag+=1;    
    }
    else if(form['password'].value !== form['retypePassword'].value){
        document.getElementById("passError").innerHTML = "*Passwords did not match.";
        flag+=1;
    }
    if(form['telephone'].value.length === 0 || (!document.forms["registrationForm"]["telephone"].value.match(regTelNo))){
        document.getElementById("TelNoError").innerHTML = "*Please enter a valid telephone number.";
        flag+=1;
    }
    if(form['email'].value.length === 0 || !document.forms["registrationForm"]["email"].value.match(regEmail)){
        document.getElementById("emailError").innerHTML = "*Please enter a valid e-mail address.";
        flag+=1;
    }
    if(form['AddressDeliveryNumber'].value.length === 0 || !document.forms["registrationForm"]["AddressDeliveryNumber"].value.match(regExpiration)){
        flag += 1;
        document.getElementById("houseError").innerHTML = "*This field is required.";
    }    
    if(form['AddressDeliveryStreet'].value.length === 0){
        flag += 1;
        document.getElementById("streetError").innerHTML = "*This field is required.";
    }    
    if(form['AddressDeliverySubdivision'].value.length === 0){
        flag += 1;
        document.getElementById("subError").innerHTML = "*This field is required.";
    }  
    if(form['AddressDeliveryCity'].value.length === 0){
        flag += 1;
        document.getElementById("cityError").innerHTML = "*This field is required.";
    }  
    if(form['AddressDeliveryPostal'].value.length === 0 || !document.forms["registrationForm"]["AddressDeliveryPostal"].value.match(regPostal)){
        document.getElementById("postalError").innerHTML = "*Invalid postal code.";
        flag+=1;
    }
    if(form['AddressDeliveryCountry'].value.length === 0){
        flag += 1;
        document.getElementById("countryError").innerHTML = "*This field is required.";
    }  
    if(form['creditName'].value.length === 0){
        flag += 1;
        document.getElementById("cNameError").innerHTML = "*This field is required.";
    } 
    else if(!form['creditName'].value.match(name)){
        flag += 1;
        document.getElementById("cNameError").innerHTML = "*Your real and own name should be in the credit card.";
    }  
    if(form['creditNumber'].value.length === 0 || !document.forms["registrationForm"]["creditNumber"].value.match(regCreditCardNumber)){
        document.getElementById("cNumError").innerHTML = "*Invalid credit card number.";
        flag+=1;
    }
    if((form['creditMonth'].value.length === 0 || form['creditYear'].value.length === 0)){
        flag += 1;
        document.getElementById("cExpireError").innerHTML = "*Invalid expiration date.";
    } 
    else if(form['creditMonth'].value <= 0 || form['creditMonth'].value >= 13 || form['creditYear'].value <= 2012 || form['creditYear'].value >= 2021
        || !document.forms["registrationForm"]["creditMonth"].value.match(regExpiration) || !document.forms["registrationForm"]["creditYear"].value.match(regExpiration)){
        flag += 1;
        document.getElementById("cExpireError").innerHTML = "*Invalid expiration date.";
    }
    if(form['addressBillNumber'].value.length === 0  || !document.forms["registrationForm"]["addressBillNumber"].value.match(regExpiration)){
        flag += 1;
        document.getElementById("cHouseError").innerHTML = "*This field is required.";
    }  
    if(form['addressBillStreet'].value.length === 0){
        flag += 1;
        document.getElementById("cStreetError").innerHTML = "*This field is required.";
    }  
    if(form['addressBillSubdivision'].value.length === 0){
        flag += 1;
        document.getElementById("cSubError").innerHTML = "*This field is required.";
    }  
    if(form['addressBillCity'].value.length === 0){
        flag += 1;
        document.getElementById("cCityError").innerHTML = "*This field is required.";
    } 
    if(form['addressBillPostal'].value.length === 0 || !document.forms["registrationForm"]["addressBillPostal"].value.match(regPostal)){
        document.getElementById("cPostalError").innerHTML = "*Invalid postal code.";
        flag+=1;
    }
    if(form['addressBillCountry'].value.length === 0){
        flag += 1;
        document.getElementById("cCountryError").innerHTML = "*This field is required.";
    }  
    
    
    if(flag >= 1){
        alert("Please double check your information.");
        return false;
    }
    else{
        form.action="registerServlet";
        return true;
    }
}


function validateManager(form){
    //alert("sdg"+form['email'].value);
    var flag = 0;
    var regUser = /\b[A-z0-9]{8,15}\b/;
    var regPass = /^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=[^\W]*\W)(?=.*[\d\W]).*$/;
    var regTelNo = /\b[0-9]{7,20}\b/;
    var regEmail = /\b[A-z0-9._]+@\b[A-z0-9.-]+\b.\b[A-z]+\b/;
    var regPostal = /\b[0-9]{3,10}\b/;
    var regExpiration = /\b[0-9]{1,4}\b/;
    
    document.getElementById("nameError").innerHTML = "";
    document.getElementById("userError").innerHTML = "";
    document.getElementById("passError").innerHTML = "";
    document.getElementById("emailError").innerHTML = "";
    document.getElementById("TelNoError").innerHTML = "";
    document.getElementById("houseError").innerHTML = "";
    document.getElementById("streetError").innerHTML = "";
    document.getElementById("subError").innerHTML = "";
    document.getElementById("cityError").innerHTML = "";
    document.getElementById("postalError").innerHTML = "";
    document.getElementById("countryError").innerHTML = "";
    
    if(form['nameFirst'].value.length === 0 || form['nameLast'].value.length === 0){
        flag += 1;
        document.getElementById("nameError").innerHTML = "*Please enter your name.";
    }  
    if(form['username'].value.length === 0 || !document.forms["createAccountForm"]["username"].value.match(regUser)){
        flag += 1;
        document.getElementById("userError").innerHTML = "*Username must be 8 - 15 characters in length.";
    } 
    if(form['password'].value.length === 0 || !document.forms["createAccountForm"]["password"].value.match(regPass)){
        document.getElementById("passError").innerHTML = "*Password must be at least 8 characters and must contain at least 1 uppercase letter, 1 number, and 1 special character.";
        flag+=1;    
    }
    else if(form['password'].value !== form['retypePassword'].value){
        document.getElementById("passError").innerHTML = "*Passwords did not match.";
        flag+=1;
    }
    if(form['telephone'].value.length === 0 || (!document.forms["createAccountForm"]["telephone"].value.match(regTelNo))){
        document.getElementById("TelNoError").innerHTML = "*Please enter a valid telephone number.";
        flag+=1;
    }
    if(form['email'].value.length === 0 || !document.forms["createAccountForm"]["email"].value.match(regEmail)){
        document.getElementById("emailError").innerHTML = "*Please enter a valid e-mail address.";
        flag+=1;
    }
    if(form['AddressDeliveryNumber'].value.length === 0 || !document.forms["createAccountForm"]["AddressDeliveryNumber"].value.match(regExpiration)){
        flag += 1;
        document.getElementById("houseError").innerHTML = "*This field is required.";
    }    
    if(form['AddressDeliveryStreet'].value.length === 0){
        flag += 1;
        document.getElementById("streetError").innerHTML = "*This field is required.";
    }    
    if(form['AddressDeliverySubdivision'].value.length === 0){
        flag += 1;
        document.getElementById("subError").innerHTML = "*This field is required.";
    }  
    if(form['AddressDeliveryCity'].value.length === 0){
        flag += 1;
        document.getElementById("cityError").innerHTML = "*This field is required.";
    }  
    if(form['AddressDeliveryPostal'].value.length === 0 || !document.forms["createAccountForm"]["AddressDeliveryPostal"].value.match(regPostal)){
        document.getElementById("postalError").innerHTML = "*Invalid postal code.";
        flag+=1;
    }
    if(form['AddressDeliveryCountry'].value.length === 0){
        flag += 1;
        document.getElementById("countryError").innerHTML = "*This field is required.";
    }  
    
    
    if(flag >= 1){
        alert("Please double check your information.");
        return false;
    }
    else{
        form.action="managerServlet";
        return true;
    }
}